home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1092 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.6 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: "Wil Evers" <wil@ittpub.nl>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: auto_ptr::is_owner()
  5. Date: 15 Apr 1996 09:37:23 PDT
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <009A0E4C263BD600.498048A4@ittpub.nl>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Mon, 15 Apr 96 12:04:23 WET
  11. X-Vms-Mail-To: IN%"std-c++@ncar.ucar.edu"
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMXJ7REy4NqrwXLNJAQHSmwIAwu1dnPxXt5LbHFET862bjPuB/fdr8WiI
  14.     AQNyvrvKiggorklgg5UOORNHWWXuoHO8Rufv4Co1P+wIGwqUPVVTQQ==
  15.     =bHbQ
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. In article <316F533D.262C89BD@cantrip.org> Nathan Myers <ncm@cantrip.org>
  19. writes:
  20. > Greg Colvin wrote:
  21. > > In article <009A0A5CE1159CC0.49802F14@ittpub.nl> "Wil Evers"
  22. > > <wil@ittpub.nl>:
  23. > > >What I definitely do not understand is why the new auto_ptr template
  24. > > >doesn't even allow us to query if it is actually owning the object
  25. > > >pointed to.
  26. > > I found it very hard to contrive examples where is_owner() would
  27. > > actually be useful. 
  28. > I agree with Greg here: any code that is intended to execute 
  29. > differently, depending on the value returned by putative member 
  30. > auto_ptr<>::is_owner(), is just bad code.
  31. >
  32. > [snip]
  33. >
  34. > The answer is: it's your responsibility to keep track of ownership
  35. > of pointers; if you can't do it manually, then automate it with 
  36. > reference counting or something.  That's not what auto_ptr<> is for;
  37. > its purpose is to make sure that the value "new T" gets destroyed.  
  38. > It does that job perfectly; don't ask it to do your job too.
  39.  
  40. Well, that's all a matter of interpretation.  The previous, simpler,
  41. implementation of auto_ptr used to do that job for me.  I used to rely on
  42. the guarantee that if it was pointing at something, it was pointing at
  43. something alive and unique.  It seemed to me that this was a reasonable
  44. assumption because the DWP stated that auto_ptr implemented the concept of
  45. `strict ownership'.
  46.  
  47. Imagine, for instance, a collection of ten heap objects in a polymorphic
  48. hierarchy, where each of those is in one of three sets.  Once every now and
  49. then, some of the objects are moved from one of the sets to another.  Why
  50. would it be bad code to implement each of these sets using an array of ten
  51. auto_ptrs?  It seems to me there is nothing inherently good or bad about
  52. such a design, it's just not supported any more.
  53.  
  54. The fact of the matter is that auto_ptr implements both a guarantee about
  55. the deletion of the pointee when the auto_ptr is destroyed *and* a concept
  56. of transferable object ownership.  The `pointer part' of the auto_ptr
  57. abstraction is well supported in its interface, while the `ownership part'
  58. no longer is.
  59.  
  60. In one of his previous articles, Greg said that he hated the idea of
  61. exposing the mutable `owner' member through an access function.  Normally,
  62. I would agree, but I think auto_ptr is a special case.  The `owner' flag
  63. has not been made mutable because it represents some implementation detail
  64. that does not effect the logical state of the object; it has been made
  65. mutable because of the problems with returning object ownership from
  66. functions.  One of the rules I use in my class designs is that if a certain
  67. attribute is part of the logical state of an object, users should be able
  68. to query it.
  69.  
  70. - Wil
  71. ---
  72. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  73.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  74.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  75.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  76.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  77. ]
  78.